package com.haoshuang.zhouzhoubang.ui.page.settled.pay

import androidx.lifecycle.rxLifeScope
import com.haoshuang.zhouzhoubang.base.request
import com.haoshuang.zhouzhoubang.model.bean.WxPayBean
import com.haoshuang.zhouzhoubang.model.bean.ZfbBean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData


class AnnualFeePayViewModel : BaseViewModel() {

    // 获取支付宝支付参数
    val getAliPayParamsData = StatefulMutableLiveData<ZfbBean>()
    fun getAliPayParams(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<ZfbBean>("api/store.team/team_create_order", *params,
                onStart = {
                    getAliPayParamsData.value = StateData.Loading
                },
                onError = { code, msg ->
                    getAliPayParamsData.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getAliPayParamsData.value = StateData.Success(it)
                })
        }
    }

    // 获取微信支付参数
    val getWechatPayParamsData = StatefulMutableLiveData<WxPayBean>()
    fun getWechatPayParams(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<WxPayBean>("api/store.team/team_create_order", *params,
                onStart = {
                    getWechatPayParamsData.value = StateData.Loading
                },
                onError = { code, msg ->
                    getWechatPayParamsData.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getWechatPayParamsData.value = StateData.Success(it)
                })
        }
    }

}